package com.lian.community.dao.user;

import com.lian.community.dao.user.po.UserPO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserDAO {

    String TABLE_NAME = "e_user";
    String INSERT_FIELDS = "password, name, salt";
    String SELECT_FIELDS = "id, password, name, salt";

    @Insert({"insert into ", TABLE_NAME, "(",INSERT_FIELDS,")","values(#{password}, #{name}, #{salt})"})
    void insert(UserPO user);

    @Select({"select", SELECT_FIELDS, " from ", TABLE_NAME, "where id = #{id}"})
    UserPO selectById(@Param("id")int id);

    @Select({"select id from ", TABLE_NAME, "where id = #{id} limit 1"})
    Integer userIsExist(@Param("id")int id);

    @Select({"select ", SELECT_FIELDS, " from ", TABLE_NAME, "where name = #{name}"})
    UserPO selectByName(@Param("name")String name);

    @Select({"select last_insert_id()"})
    Integer lastInsertId();




}
